{extend name="common@base/common" /}

{block name="style"}
<link href="__CSS__/main.min.css" rel="stylesheet" type="text/css"/>
<link href="__ZUI__/lib/uploader/zui.uploader.css" rel="stylesheet">
{/block}

{block name="body"}
<div class="container">
  <ol class="breadcrumb">
      <li><a href="{:url('index/index')}">演示首页</a></li>
      <li>文件上传</li>
  </ol>
<section class="demo-section">

<div id="pageContent">



<article><p>文件上传视图提供文件列表管理和文件批量上传功能，允许拖拽（需要 HTML5 支持）来添加上传文件，支持大文件分片上传，优先使用 HTML5 文件上传功能，旧的浏览器自动使用 Flash 和 Silverlight 的方式兼容，还可用轻松搭配七牛云存储 Javascript SDK 使用。该插件基于 <a href="http://www.plupload.com/" target="_blank">plupload</a> 开发。</p><div class="alert alert-warning">
  <h4>兼容性提示</h4>
  <p>文件上传视图不支持 IE9 以下的浏览器。</p>
</div></article>

<section><header><h3>综合示例</h3></header><article><p>在下面的例子中点击 “选择文件” 按钮或者拖拽文件到页面指示区域来选择文件，点击 “开始上传” 按钮来批量上传文件到服务器。</p><div class="alert alert-primary">
  <h4>提示</h4>
  <p>在此页面内的测试文件上传时，你的文件会上传到服务器（<a target="_blank" class="alert-link text-hostname" href="http://httpbin.org/post"><strong>http://httpbin.org/</strong></a>），但不会在服务器保存你的文件，你可以放心进行测试。</p>
</div><h4>普通文件列表</h4><div class="example">
  <div id="uploaderExample" class="uploader file-drag-area uploader-rename" data-auto-upload="true" data-drop-placeholder="将文件拖放至在此处。">
    <div class="uploader-files file-list file-rename-by-click" data-drag-placeholder="请拖拽文件到此处"></div>
    <button type="button" class="btn btn-primary uploader-btn-browse"><i class="icon icon-cloud-upload"></i> 选择文件</button>
  <div class="uploader-btn-browse uploader-btn-hidden" style="z-index: 1;"></div><div id="html5_1dob115ts10s133r1ked1mu82nf4_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: -1px; left: -1px; width: 1px; height: 1px; overflow: hidden; z-index: 0;"><input id="html5_1dob115ts10s133r1ked1mu82nf4" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="" tabindex="-1"></div></div>
</div><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">"uploaderExample"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-list"</span><span class="pln"> </span><span class="atn">data-drag-placeholder</span><span class="pun">=</span><span class="atv">"请拖拽文件到此处"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-primary uploader-btn-browse"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-cloud-upload"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> 选择文件</span><span class="tag">&lt;/button&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code></pre><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pln">$</span><span class="pun">(</span><span class="str">'#uploaderExample'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">({</span><span class="pln">
    autoUpload</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">,</span><span class="pln">            </span><span class="com">// 当选择文件后立即自动进行上传操作</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'your/file/upload/url'</span><span class="pln">  </span><span class="com">// 文件上传提交地址</span><span class="pln">
</span><span class="pun">});</span></code></pre><h4>大号文件列表</h4><div class="example">
  <div id="uploaderExample2" class="uploader file-drag-area uploader-rename" data-drop-placeholder="将文件拖放至在此处。">
    <div class="uploader-message text-center">
      <div class="content"></div>
      <button type="button" class="close">×</button>
    </div>
    <div class="uploader-files file-list file-list-lg file-rename-by-click" data-drag-placeholder="请拖拽文件到此处"></div>
    <div class="uploader-actions">
      <div class="uploader-status pull-right text-muted"></div>
      <button type="button" class="btn btn-link uploader-btn-browse"><i class="icon icon-plus"></i> 选择文件</button>
      <button type="button" class="btn btn-link uploader-btn-start"><i class="icon icon-cloud-upload"></i> 开始上传</button>
    </div>
  <div class="uploader-btn-browse uploader-btn-hidden" style="z-index: 1;"></div><div id="html5_1dob115u3mt4193i1ku81gqpabr7_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: -1px; left: -1px; width: 1px; height: 1px; overflow: hidden; z-index: 0;"><input id="html5_1dob115u3mt4193i1ku81gqpabr7" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="" tabindex="-1"></div></div>
</div><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">'uploaderExample2'</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="pln"> </span><span class="atn">data-ride</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="pln"> </span><span class="atn">data-url</span><span class="pun">=</span><span class="atv">"your/file/upload/url"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-message text-center"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"content"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"close"</span><span class="tag">&gt;</span><span class="pln">×</span><span class="tag">&lt;/button&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-files file-list file-list-lg"</span><span class="pln"> </span><span class="atn">data-drag-placeholder</span><span class="pun">=</span><span class="atv">"请拖拽文件到此处"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-actions"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-status pull-right text-muted"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link uploader-btn-browse"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-plus"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> 选择文件</span><span class="tag">&lt;/button&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link uploader-btn-start"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-cloud-upload"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> 开始上传</span><span class="tag">&lt;/button&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code></pre><h4>网格视图</h4><div class="example">
  <div id="uploaderExample3" class="uploader file-drag-area uploader-rename" data-drop-placeholder="将文件拖放至在此处。">
    <div class="uploader-message text-center">
      <div class="content"></div>
      <button type="button" class="close">×</button>
    </div>
    <div class="uploader-files file-list file-list-grid file-rename-by-click"></div>
    <div>
      <hr class="divider">
      <div class="uploader-status pull-right text-muted"></div>
      <button type="button" class="btn btn-link uploader-btn-browse"><i class="icon icon-plus"></i> 选择文件</button>
      <button type="button" class="btn btn-link uploader-btn-start"><i class="icon icon-cloud-upload"></i> 开始上传</button>
    </div>
  <div class="uploader-btn-browse uploader-btn-hidden" style="z-index: 1;"></div><div id="html5_1dob115u71cd81vuu1qf10md1i0ca_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: -1px; left: -1px; width: 1px; height: 1px; overflow: hidden; z-index: 0;"><input id="html5_1dob115u71cd81vuu1qf10md1i0ca" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="" tabindex="-1"></div></div>
</div><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">'uploaderExample3'</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="pln"> </span><span class="atn">data-ride</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="pln"> </span><span class="atn">data-url</span><span class="pun">=</span><span class="atv">"your/file/upload/url"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-message text-center"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"content"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"close"</span><span class="tag">&gt;</span><span class="pln">×</span><span class="tag">&lt;/button&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-files file-list file-list-grid"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;div&gt;</span><span class="pln">
    </span><span class="tag">&lt;hr</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"divider"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-status pull-right text-muted"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link uploader-btn-browse"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-plus"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> 选择文件</span><span class="tag">&lt;/button&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link uploader-btn-start"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-cloud-upload"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> 开始上传</span><span class="tag">&lt;/button&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code></pre></article></section>



<section><header><h3>使用</h3></header><article><h4>引入资源</h4><p>文件上传为独立组件，你需要从本地或 CDN 单独引入 lib 目录下的资源：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;link</span><span class="pln"> </span><span class="atn">href</span><span class="pun">=</span><span class="atv">"lib/uploader/zui.uploader.min.css"</span><span class="pln"> </span><span class="atn">rel</span><span class="pun">=</span><span class="atv">"stylesheet"</span><span class="tag">&gt;</span><span class="pln">
</span><span class="tag">&lt;script</span><span class="pln"> </span><span class="atn">src</span><span class="pun">=</span><span class="atv">"lib/uploader/zui.uploader.min.js"</span><span class="tag">&gt;&lt;/script&gt;</span></code></pre><h4>初始化 uploader</h4><p>方式一，使用 <code>$().uploader()</code>：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">"myUploader"</span><span class="tag">&gt;</span><span class="pln">
  ...
</span><span class="tag">&lt;/div&gt;</span></code></pre><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="kwd">var</span><span class="pln"> options </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    </span><span class="com">// 初始化选项</span><span class="pln">
</span><span class="pun">};</span><span class="pln">
$</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">(</span><span class="pln">options</span><span class="pun">);</span></code></pre><p>方式二，使用 <code>[data-ride="uploader"]</code>：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="pln"> </span><span class="atn">data-ride</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="pln"> </span><span class="atn">data-auto-upload</span><span class="pun">=</span><span class="atv">"true"</span><span class="tag">&gt;</span><span class="pln">
  ...
</span><span class="tag">&lt;/div&gt;</span></code></pre><h4>获取 uploader 对象</h4><p>当初始化之后你可以通过 <code>$().data('zui.uploader')</code> 获取 <code>uploader</code> 对象：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="kwd">var</span><span class="pln"> uploader </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.uploader'</span><span class="pun">);</span></code></pre></article></section>

<section><header><h3>选项</h3></header><article><p>在进行初始化时允许传入一个对象参数作为初始化选项。可以使用的选项如下：</p><div class="table-responsive"><table class="table table-bordered">
  <thead>
    <tr>
      <th style="width: 100px">选项</th>
      <th style="width: 130px">名称</th>
      <th style="width: 110px">值</th>
      <th>描述</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>drop_element</code></td>
      <td>触发文件拖放的元素</td>
      <td>默认 <code>'self'</code></td>
      <td>
        <p>所有可用的值如下：</p>
        <ul>
          <li><code>'self'</code>：使用 uploader 本身作为拖放文件的触发元素；</li>
          <li><code>'fileList'</code>：使用文件列表；</li>
          <li>jQuery 对象；</li>
          <li>使用 jQuery 选择器来指定触发元素。</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>browse_button</code></td>
      <td>触发打开选择文件对话框按钮</td>
      <td>默认 <code>'hidden'</code></td>
      <td>
        <p>所有可用的值如下：</p>
        <ul>
          <li><code>null</code> 或 <code>'hidden'</code>：不显示按钮，此时仍然可以使用 '.uploader-btn-browse' 类来标记上传按钮；</li>
          <li><code>'&gt;.uploader-btn-browse'</code>：在 <code>.uploader</code> 内查找包含类 <code>.uploader-btn-browse</code> 的元素；</li>
          <li><code>'#uploaderBtn'</code>：在页面内查找 ID 为 <code>uploaderBtn</code> 的元素；</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>url</code></td>
      <td>文件上传地址</td>
      <td>必填</td>
      <td>服务器端处理文件上传的地址，可用为完整地址或者相对于当前页面的相对地址。</td>
    </tr>
    <tr>
      <td><code>qiniu</code></td>
      <td>七牛 SDK 配置</td>
      <td>可选</td>
      <td>
        <p>如果要使用七牛 SDK 来上传文件，则需要配置此选项，否则请留空。七牛文件上传参见本文后续内容。</p>
      </td>
    </tr>
    <tr>
      <td><code>filters</code></td>
      <td>文件过滤器</td>
      <td>可选</td>
      <td>
        <p>用来过滤文件的类型、大小等。该选项为一个对象，可以包含如下属性的一项或全部：</p>
        <ul>
          <li><code>mime_types</code>：用来设定允许上传的文件类型，该值为一个对象数组，每个对象包含 <code>title</code> 和 <code>extensions</code> 属性；</li>
          <li><code>max_file_size</code>：最大允许上传的文件大小，例如 <code>1024</code>，单位为字节（b），也可用为一个字符串，包含数值或单位，例如 <code>128kb</code>；</li>
          <li><code>prevent_duplicates</code>：是否允许选取重复的文件，默认为 <code>true</code> 不允许，如果两个文件名和大小都相同则被认为是重复的文件；</li>
        </ul>
        <p>此选项的一个完整示例如下：</p>
        <pre class="prettyprint prettyprinted" style=""><code><span class="pun">{</span><span class="pln">
    </span><span class="com">// 只允许上传图片或图标（.ico）</span><span class="pln">
    mime_types</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="pln">
        </span><span class="pun">{</span><span class="pln">title</span><span class="pun">:</span><span class="pln"> </span><span class="str">'图片'</span><span class="pun">,</span><span class="pln"> extensions</span><span class="pun">:</span><span class="pln"> </span><span class="str">'jpg,gif,png'</span><span class="pun">},</span><span class="pln">
        </span><span class="pun">{</span><span class="pln">title</span><span class="pun">:</span><span class="pln"> </span><span class="str">'图标'</span><span class="pun">,</span><span class="pln"> extensions</span><span class="pun">:</span><span class="pln"> </span><span class="str">'ico'</span><span class="pun">}</span><span class="pln">
    </span><span class="pun">],</span><span class="pln">
    </span><span class="com">// 最大上传文件为 1MB</span><span class="pln">
    max_file_size</span><span class="pun">:</span><span class="pln"> </span><span class="str">'1mb'</span><span class="pun">,</span><span class="pln">
    </span><span class="com">// 不允许上传重复文件</span><span class="pln">
    prevent_duplicates</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">true</span><span class="pln">
</span><span class="pun">}</span></code></pre>
      </td>
    </tr>
    <tr>
      <td><code>fileList</code></td>
      <td>文件列表容器元素</td>
      <td>默认为 <code>''</code></td>
      <td>
        <p>可选值还包括：</p>
        <ul>
          <li><code>'large'</code>：使用大号文件列表；</li>
          <li><code>'grid'</code>：使用网格文件列表；</li>
          <li><code>'&gt;.file-list'</code>，在 <code>.uploader</code> 内查找包含 <code>.file-list</code> 类的元素作为文件列表容器；</li>
          <li><code>'#myFileList'</code>，在页面内查找 ID 为 <code>myFileList</code> 的元素作为文件列表容器；</li>
          <li><code>&lt;div class="uploader-files file-list"&gt;&lt;/div&gt;</code>：使用指定的 HTML 来创建文件列表容器元素。</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>fileTemplate</code></td>
      <td>文件显示元素模板</td>
      <td>默认 <code>''</code></td>
      <td>当设置为空值时则使用默认模板 <code>&lt;div class="file"&gt;&lt;div class="file-progress-bar"&gt;&lt;/div&gt;&lt;div class="file-wrapper"&gt;&lt;div class="file-icon"&gt;&lt;i class="icon icon-file-o"&gt;&lt;/i&gt;&lt;/div&gt;&lt;div class="content"&gt;&lt;div class="file-name"&gt;&lt;/div&gt;&lt;div class="file-size small text-muted"&gt;0KB&lt;/div&gt;&lt;/div&gt;&lt;div class="actions"&gt;&lt;div class="file-status" data-toggle="tooltip"&gt;&lt;i class="icon"&gt;&lt;/i&gt; &lt;span class="text"&gt;&lt;/span&gt;&lt;/div&gt;&lt;a data-toggle="tooltip" class="btn btn-link btn-download-file" target="_blank"&gt;&lt;i class="icon icon-download-alt"&gt;&lt;/i&gt;&lt;/a&gt;&lt;button type="button" data-toggle="tooltip" class="btn btn-link btn-reset-file" title="Repeat"&gt;&lt;i class="icon icon-repeat"&gt;&lt;/i&gt;&lt;/button&gt;&lt;button type="button" data-toggle="tooltip" class="btn btn-link btn-rename-file" title="Rename"&gt;&lt;i class="icon icon-pencil"&gt;&lt;/i&gt;&lt;/button&gt;&lt;button type="button" data-toggle="tooltip" title="Remove" class="btn btn-link btn-delete-file"&gt;&lt;i class="icon icon-trash text-danger"&gt;&lt;/i&gt;&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</code></td>
    </tr>
    <tr>
      <td><code>fileFormater</code></td>
      <td>文件显示元素格式化函数</td>
      <td>函数，可选</td>
      <td>
        <p><code>function($file, file, status){}</code></p>
        <p>其中各参数含义如下：</p>
        <ul>
          <li><code>$file</code>：当前用于显示文件内容的元素（jQuery 对象）；</li>
          <li><code>file</code>：当前用于显示的文件对象；</li>
          <li><code>status</code>：当前文件状态；</li>
        </ul>
        <p>如果不指定此选项，则使用默认的格式化函数。</p>
      </td>
    </tr>
    <tr>
      <td><code>fileIconCreator</code></td>
      <td>文件图标生成器函数</td>
      <td>函数，可选</td>
      <td>
        <p><code>function(fileType, file, uploader){}</code></p>
        <p>其中各参数含义如下：</p>
        <ul>
          <li><code>fileType</code>：当前文件类型，例如 <code>'image/gif'</code>；</li>
          <li><code>file</code>：当前文件对象；</li>
          <li><code>uploader</code>：当前 uploader 对象；</li>
        </ul>
        <p>在此选项指定的函数返回用于展示文件图标的 HTML 内容。如果不指定此选项，则使用默认的图标生成器函数。</p>
      </td>
    </tr>
    <tr>
      <td><code>staticFiles</code></td>
      <td>初始静态文件对象数组</td>
      <td>对象数组</td>
      <td>
        <p>在此选项中设定文件上传控件初始化显示在文件列表中的静态文件条目。对象数组的对象格式如下：</p>
        <pre class="prettyprint prettyprinted" style=""><code><span class="pun">{</span><span class="pln">
    id</span><span class="pun">,</span><span class="pln">              </span><span class="com">// 文件id</span><span class="pln">
    name</span><span class="pun">,</span><span class="pln">            </span><span class="com">// 文件名，例如"myfile.gif"</span><span class="pln">
    type</span><span class="pun">,</span><span class="pln">            </span><span class="com">// 文件类型，例如"image/jpeg"</span><span class="pln">
    size</span><span class="pun">,</span><span class="pln">            </span><span class="com">// 文件大小，单位为字节，当启用了客户端压缩功能后，该值可能会改变</span><span class="pln">
    origSize</span><span class="pun">,</span><span class="pln">        </span><span class="com">// 文件的原始大小，单位为字节</span><span class="pln">
    lastModifiedDate </span><span class="com">// 文件的最后修改时间</span><span class="pln">
</span><span class="pun">}</span></code></pre>
      </td>
    </tr>
    <tr>
      <td><code>rename</code></td>
      <td>是否支持文件重命名</td>
      <td>默认为 <code>true</code></td>
      <td></td>
    </tr>
    <tr>
      <td><code>renameExtension</code></td>
      <td>是否允许重命名文件扩展名</td>
      <td>默认为 <code>false</code></td>
      <td></td>
    </tr>
    <tr>
      <td><code>renameByClick</code></td>
      <td>是否点击文件名即可重命名</td>
      <td>默认为 <code>true</code></td>
      <td></td>
    </tr>
    <tr>
      <td><code>autoUpload</code></td>
      <td>是否自动上传文件</td>
      <td>默认为 <code>false</code></td>
      <td></td>
    </tr>
    <tr>
      <td><code>browseByClickList</code></td>
      <td>是否点击文件列表上传文件</td>
      <td>默认为 <code>false</code></td>
      <td>如果设置为 <code>true</code>，则可用通过点击文件列表来触发打开文件选择对话框事件，此时可能会忽略文件条目上的一些事件。</td>
    </tr>
    <tr>
      <td><code>dropPlaceholder</code></td>
      <td>拖放时的提示文本</td>
      <td>默认为 <code>true</code></td>
      <td>设定字符串来指定用于拖放时的提示文本，如果设置为 <code>true</code> 则显示默认的提示文本。</td>
    </tr>
    <tr>
      <td><code>previewImageIcon</code></td>
      <td>使用图片预览图作为图标</td>
      <td>默认 <code>true</code></td>
      <td>如果设置为 <code>true</code>，当文件类型为图片时使用图片的预览图代替文件图标。</td>
    </tr>
    <tr>
      <td><code>sendFileName</code></td>
      <td>发送文件名称</td>
      <td>默认为 <code>true</code></td>
      <td>
        <p>可选值如下：</p>
        <ul>
          <li><code>true</code>，使用表单 <code>'name'</code> 字段发送文件名称；</li>
          <li><code>false</code>，不发送文件名称；</li>
          <li>指定一个字符串作为表单字段名称来发送文件名。</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>sendFileId</code></td>
      <td>发送文件 ID</td>
      <td>默认为 <code>true</code></td>
      <td>
        <p>可选值如下：</p>
        <ul>
          <li><code>true</code>，使用表单 <code>'name'</code> 字段发送文件 ID；</li>
          <li><code>false</code>，不发送文件 ID；</li>
          <li>指定一个字符串作为表单字段 ID 来发送文件名。</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>responseHandler</code></td>
      <td>服务器响应处理</td>
      <td><code>true</code>（默认）或函数</td>
      <td>
        <p>当设置为 <code>true</code> 时，使用默认的服务器响应处理函数（解析 json 对象并判断上传结果）；</p>
        <p>当设置为回调函数时，函数 <code>function(responseObject, file){}</code> 参数定义如下：</p>
        <ul>
          <li><code>responseObject</code>：服务器响应数据对象；</li>
          <li><code>file</code>：当前上传的文件对象。</li>
        </ul>
        <p>在此函数内返回的任何文本内容都会当作错误的消息文本并且视此次上传失败。</p>
      </td>
    </tr>
    <tr>
      <td><code>limitFilesCount</code></td>
      <td>限制文件上传数目</td>
      <td><code>false</code>（默认）或数字</td>
      <td></td>
    </tr>
    <tr>
      <td><code>deleteConfirm</code></td>
      <td>移除文件进行确认</td>
      <td><code>false</code>（默认）或字符串</td>
      <td>
        <p>可选值如下：</p>
        <ul>
          <li><code>false</code>，不进行确认；</li>
          <li><code>true</code>，进行确认；</li>
          <li>使用字符串来作为消息进行确认。</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>autoResetFails</code></td>
      <td>是否自动重置上传失败的文件</td>
      <td><code>false</code>（默认）</td>
      <td>
        <p>可选值如下：</p>
        <ul>
          <li><code>false</code>，不自动重置上传失败的文件；</li>
          <li><code>true</code>，自动重置上传失败的文件；</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>removeUploaded</code></td>
      <td>移除已上传文件</td>
      <td><code>false</code>（默认）或 <code>true</code></td>
      <td></td>
    </tr>
    <tr>
      <td><code>statusCreator</code></td>
      <td>上传状态文本生成器</td>
      <td>函数，可选</td>
      <td>
        <p><code>function(total, state, uploader){}</code></p>
        <p>其中各参数含义如下：</p>
        <ul>
          <li><code>total</code>：当前文件队列进度对象；</li>
          <li><code>state</code>：当前文件队列状态；</li>
          <li><code>uploader</code>：当前 uploader 对象；</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>previewImageSize</code></td>
      <td>预览图尺寸</td>
      <td><code>{width, height}</code></td>
      <td>默认 <code>{width: 200, height: 200}</code></td>
    </tr>
    <tr>
      <td><code>uploadedMessage</code></td>
      <td>显示上传成功消息</td>
      <td>默认 <code>true</code></td>
      <td>
        <p>所有可用的值如下：</p>
        <ul>
          <li><code>true</code>：使用默认的提示消息；</li>
          <li><code>false</code>：不显示提示消息；</li>
          <li>指定一个字符串用来格式化提示消息，例如 <code>已上传 {uploaded} 个文件，{failed} 个文件上传失败。</code>；</li>
          <li>指定一个函数来返回格式化提示消息，函数定义为：<code>function(result){}</code>，其中参数 <code>result</code> 为 <code>{uploaded, failed}</code>，包含了此次上传成功的数目和失败的数目。</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>deleteActionOnDone</code></td>
      <td>是否允许删除上传成功的文件</td>
      <td>默认 <code>false</code></td>
      <td>
        <p>所有可用的值如下：</p>
        <ul>
          <li><code>false</code>：不允许从文件列表删除上传成功的文件；</li>
          <li>
            <p>指定一个函数来决定是否删除文件，函数定义为 <code>function(file, doRemoveFile){}</code>，在此函数内返回 <code>true</code> 来确认删除文件，其中函数参数定义如下：</p>
            <ul>
              <li><code>file</code>，将要删除的文件对象；</li>
              <li><code>doRemoveFile</code>，一个回调函数对象，调用此函数则会直接删除。</li>
            </ul>
            <p>当文件上传成功之后如果想删除文件通常需要先在服务器将文件删除，你可用在此回调函数内向服务器发起请求，然后再从文件上传视图的文件列表中移除。</p>
          </li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>renameActionOnDone</code></td>
      <td>是否允许重命名上传成功的文件</td>
      <td>默认 <code>false</code></td>
      <td>
        <p>所有可用的值如下：</p>
        <ul>
          <li><code>false</code>：不允许重命名上传成功的文件；</li>
          <li>
            <p>指定一个函数来决定是否重命名文件，函数定义为 <code>function(file, filename, doRenameFile){}</code>，在此函数内返回 <code>true</code> 来确认重命名文件，其中函数参数定义如下：</p>
            <ul>
              <li><code>file</code>，将要重命名的文件对象；</li>
              <li><code>filename</code>，新的文件名；</li>
              <li><code>doRenameFile</code>，一个回调函数对象，调用此函数则会直接重命名。</li>
            </ul>
            <p>当文件上传成功之后如果想重命名文件通常需要先在服务器将文件重命名，你可用在此回调函数内向服务器发起请求，然后再在文件列表中更改文件名称。</p>
          </li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>headers</code></td>
      <td>自定义头信息</td>
      <td>默认 <code>{}</code></td>
      <td>使用一个对象中的属性和值作为键值对来定义上传到服务器请求的头信息。HTML 4 的上传方式不支持自定义头信息。</td>
    </tr>
    <tr>
      <td><code>multipart</code></td>
      <td>使用 <code>multipart/form-data</code></td>
      <td>默认为 <code>true</code></td>
      <td>如果为 <code>true</code>，则上传文件时以 <code>multipart/form-data</code> 来提交表单到服务器，如果为 <code>false</code> 则使用二进制的形式来上传文件。使用二进制的形式上传文件可能会存在问题，推荐使用 <code>multipart/form-data</code> 的形式。</td>
    </tr>
    <tr>
      <td><code>multipart_params</code></td>
      <td>multipart 附加参数</td>
      <td>函数或对象，默认 <code>{}</code></td>
      <td>
        <p>当提交表单时附加到请求中的参数，如果是 php 服务器端可用使用 <code>$_POST</code> 获取到这些参数。例如：</p>
        <pre class="prettyprint prettyprinted" style=""><code><span class="pun">{</span><span class="pln">
    foo</span><span class="pun">:</span><span class="pln"> </span><span class="str">'foo'</span><span class="pun">,</span><span class="pln">
    bar</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="str">'bar1'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'bar2'</span><span class="pun">],</span><span class="pln">
    test</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        attr1</span><span class="pun">:</span><span class="pln"> </span><span class="str">'attr1 value'</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span></code></pre>
        <p>当设置为回调函数时会在提交文件之前调用，使用返回值作为附加参数提交到服务器，该回调函数包含一个参数为当前提交的文件对象。</p>
        <pre class="prettyprint prettyprinted" style=""><code><span class="kwd">function</span><span class="pun">(</span><span class="pln">file</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">params</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    </span><span class="kwd">return</span><span class="pln"> </span><span class="pun">{</span><span class="pln">filename</span><span class="pun">:</span><span class="pln"> file</span><span class="pun">.</span><span class="pln">name</span><span class="pun">,</span><span class="pln"> extension</span><span class="pun">:</span><span class="pln"> file</span><span class="pun">.</span><span class="pln">ext</span><span class="pun">};</span><span class="pln">
</span><span class="pun">}</span></code></pre>
        <p>回调函数参数定义如下：</p>
        <ul>
          <li><code>file</code>：当前准备上传的文件对象；</li>
          <li><code>params</code>：当前默认的参数对象，你可以修改这个对象并返回作为新的参数对象。</li>
        </ul>
      </td>
    </tr>
    <tr>
      <td><code>max_retries</code></td>
      <td>最大尝试次数</td>
      <td>默认 <code>3</code></td>
      <td>当上传失败时的最大尝试次数，如果为 <code>0</code> 表示不重试。</td>
    </tr>
    <tr>
      <td><code>chunk_size</code></td>
      <td>分片上传大小</td>
      <td>默认 <code>1mb</code></td>
      <td>如果此值为一个数字，则默认单位为字节，如果为 <code>0</code>，则表示不启用分片上传。</td>
    </tr>
    <tr>
      <td><code>resize</code></td>
      <td>图片修改设置</td>
      <td>默认 <code>{}</code></td>
      <td>
        <p>使用一个对象来设置如果在上传图片之前对图片进行修改。该对象可以包含如下属性的一项或全部：</p>
        <ul>
          <li><code>width</code>：图片压缩后的宽度，如果不指定此属性则保持图片的原始宽度；</li>
          <li><code>height</code>：图片压缩后的高度，如果不指定此属性则保持图片的原始高度；</li>
          <li><code>crop</code>：是否对图片进行裁剪；</li>
          <li><code>quality</code>：图片压缩质量，可取值为 <code>0~100</code>，数值越大，图片质量越高，压缩比例越小，文件体积也越大，默认为 <code>90</code>，只对 <code>.jpg</code> 图片有效；</li>
          <li><code>preserve_headers</code>：是否保留图片的元数据，默认为 <code>true</code> 保留，如果为 <code>false</code> 不保留。</li>
        </ul>
        <p>该选项的一个完整示例如下：</p>
        <pre class="prettyprint prettyprinted" style=""><code><span class="pun">{</span><span class="pln">
    width</span><span class="pun">:</span><span class="pln"> </span><span class="lit">128</span><span class="pun">,</span><span class="pln">
    height</span><span class="pun">:</span><span class="pln"> </span><span class="lit">128</span><span class="pun">,</span><span class="pln">
    crop</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">,</span><span class="pln">
    quuality</span><span class="pun">:</span><span class="pln"> </span><span class="lit">90</span><span class="pun">,</span><span class="pln">
    preserve_headers</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">false</span><span class="pln">
</span><span class="pun">}</span></code></pre>
      </td>
    </tr>
    <tr>
      <td><code>multi_selection</code></td>
      <td>是否可用一次选取多个文件</td>
      <td>默认 <code>true</code></td>
    </tr>
    <tr>
      <td><code>unique_names</code></td>
      <td>为文件分配唯一文件名</td>
      <td>默认 <code>false</code></td>
      <td>如果为 <code>true</code>，则会为每一个上传的文件生成一个唯一的文件名，并作为额外的参数提交到服务器。</td>
    </tr>
    <tr>
      <td><code>runtimes</code></td>
      <td>文件上传方式</td>
      <td>默认 <code>html5,flash,silverlight,html4</code></td>
      <td>默认情况下会根据浏览器支持的情况自动配置此参数。</td>
    </tr>
    <tr>
      <td><code>file_data_name</code></td>
      <td>文件域在表单中的名称</td>
      <td>默认 <code>'file'</code></td>
      <td>如果为 <code>'file'</code>，则可用在服务器通过 <code>$_FILES['file']</code> 来获取上传的文件信息。</td>
    </tr>
    <tr>
      <td><code>flash_swf_url</code></td>
      <td>flash 上传组件地址</td>
      <td>默认为 <code>lib/uploader/Moxie.swf</code></td>
      <td>请确保在文件上传页面能够通过此地址访问到此文件。</td>
    </tr>
    <tr>
      <td><code>silverlight_xap_url</code></td>
      <td>silverlight 上传组件地址</td>
      <td>默认为 <code>lib/uploader/Moxie.xap</code></td>
      <td>请确保在文件上传页面能够通过此地址访问到此文件。</td>
    </tr>
    <tr>
      <td><code>lang</code></td>
      <td>界面语言</td>
      <td>默认 <code>''</code></td>
      <td>
        <p>默认情况下设置为空值，会从浏览器 <code>&lt;html lang=""&gt;</code> 属性上获取语言设置，但有也可以手动指定为以下选项：</p>
        <ul>
          <li><code>'zh_cn'</code>：简体中文；</li>
          <li><code>'zh_tw'</code>：繁体中文；</li>
          <li><code>'en'</code>'：英文；</li>
          <li><code>{...}</code>：使用一个对象来自定义语言，自定义语言对象应该包含的属性值参考内置语言对象 <code>$.zui.Uploader.LANG</code>。</li>
        </ul>
      </td>
    </tr>
  </tbody>
</table></div></article></section>

















<section><header><h3>对象及属性</h3></header><article><h4>文件队列及文件状态</h4><p><code>$.zui.Uploader.STATUS</code> 对象提供一些预设的属性来表示文件队列和文件的各个状态信息。</p><div class="table-responsive"><table class="table table-bordered">
  <thead>
    <tr>
      <th>状态</th>
      <th>值</th>
      <th>描述</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>STOPPED</code></td>
      <td><code>1</code></td>
      <td>文件队列还没有开始上传，或者上传已暂停或已上传完成。</td>
    </tr>
    <tr>
      <td><code>STARTED</code></td>
      <td><code>2</code></td>
      <td>文件队列正在上传中。</td>
    </tr>
    <tr>
      <td><code>QUEUED</code></td>
      <td><code>1</code></td>
      <td>文件已被添加到上传队列中等待上传。</td>
    </tr>
    <tr>
      <td><code>UPLOADING</code></td>
      <td><code>2</code></td>
      <td>文件正在上传中。</td>
    </tr>
    <tr>
      <td><code>FAILED</code></td>
      <td><code>4</code></td>
      <td>文件上传失败。</td>
    </tr>
    <tr>
      <td><code>DONE</code></td>
      <td><code>5</code></td>
      <td>文件已上传到服务器。</td>
    </tr>
  </tbody>
</table></div><h4>文件对象属性和方法</h4><p>在很多回调函数中会给出文件对象信息。</p><div class="table-responsive"><table class="table table-bordered">
  <thead>
    <tr>
      <th>属性/方法</th>
      <th>说明</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>id</code></td>
      <td>文件 ID</td>
    </tr>
    <tr>
      <td><code>name</code></td>
      <td>文件名称，例如 <code>'myFile.jpg'</code></td>
    </tr>
    <tr>
      <td><code>type</code></td>
      <td>文件类型，例如 <code>'image/jpeg'</code></td>
    </tr>
    <tr>
      <td><code>ext</code></td>
      <td>文件扩展名，例如 <code>'.gif'</code></td>
    </tr>
    <tr>
      <td><code>isImage</code></td>
      <td>文件是否为图片</td>
    </tr>
    <tr>
      <td><code>previewImage</code></td>
      <td>图片文件的预览图地址</td>
    </tr>
    <tr>
      <td><code>size</code></td>
      <td>文件大小，单位为字节（b）</td>
    </tr>
    <tr>
      <td><code>origSize</code></td>
      <td>文件的原始大小，单位为字节（b）</td>
    </tr>
    <tr>
      <td><code>loaded</code></td>
      <td>文件已上传部分的大小，单位为字节（b）</td>
    </tr>
    <tr>
      <td><code>percent</code></td>
      <td>文件已上传部分所占的百分比，例如 <code>50</code> 表示已上传了 50%</td>
    </tr>
    <tr>
      <td><code>status</code></td>
      <td>文件的状态，该值为 <code>$.zui.Uploader.STATUS</code> 对象上的一个属性值。</td>
    </tr>
    <tr>
      <td><code>lastModifiedDate</code></td>
      <td>文件上次修改的时间</td>
    </tr>
    <tr>
      <td><code>getNative()</code></td>
      <td>获取原生的文件对象</td>
    </tr>
    <tr>
      <td><code>destroy()</code></td>
      <td>销毁文件对象</td>
    </tr>
  </tbody>
</table></div><p>并不保证任何时候文件对象中都包含以上全部属性。</p><h4>文件上传队列进度信息</h4><p>文件上传队列进度信息为一个对象，包含如下属性：</p><div class="table-responsive"><table class="table table-bordered">
  <thead>
    <tr>
      <th>属性</th>
      <td>说明</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>size</code></td>
      <td>上传队列中所有文件的总大小，单位为字节（b）</td>
    </tr>
    <tr>
      <td><code>loaded</code></td>
      <td>上传队列中已上传文件的总大小，单位为字节（b）</td>
    </tr>
    <tr>
      <td><code>uploaded</code></td>
      <td>上传队列中已上传成功的文件数目</td>
    </tr>
    <tr>
      <td><code>failed</code></td>
      <td>上传队列上传失败的文件数目</td>
    </tr>
    <tr>
      <td><code>queued</code></td>
      <td>上传队列中等待上传或者正在上传的文件数目</td>
    </tr>
    <tr>
      <td><code>percent</code></td>
      <td>上传队列已完成上传占所有文件的百分比，为一个 <code>0~100</code> 数值，如果为 <code>50</code>，表示已上传了 <code>50%</code></td>
    </tr>
    <tr>
      <td><code>bytesPerSec</code></td>
      <td>上传的速度，单位为字节/秒，即 <code>b/s</code></td>
    </tr>
  </tbody>
</table></div><h4>错误代码属性</h4><p>这些属性在 <code>$.zui.Uploader.ERRORS</code> 对象上。</p><div class="table-responsive"><table class="table table-bordered">
  <thead>
    <tr>
      <th>属性</th>
      <th>值</th>
      <th>描述</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>GENERIC_ERROR</code></td>
      <td><code>-100</code></td>
      <td>通用错误</td>
    </tr>
    <tr>
      <td><code>HTTP_ERROR</code></td>
      <td><code>-200</code></td>
      <td>HTTP 网络错误</td>
    </tr>
    <tr>
      <td><code>IO_ERROR</code></td>
      <td><code>-300</code></td>
      <td>文件读写错误，例如无法读取所选择的文件</td>
    </tr>
    <tr>
      <td><code>SECURITY_ERROR</code></td>
      <td><code>-400</code></td>
      <td>安全错误</td>
    </tr>
    <tr>
      <td><code>INIT_ERROR</code></td>
      <td><code>-500</code></td>
      <td>初始化时发生错误</td>
    </tr>
    <tr>
      <td><code>FILE_SIZE_ERROR</code></td>
      <td><code>-600</code></td>
      <td>文件大小不符合要求</td>
    </tr>
    <tr>
      <td><code>FILE_EXTENSION_ERROR</code></td>
      <td><code>-601</code></td>
      <td>文件类型不符合要求</td>
    </tr>
    <tr>
      <td><code>FILE_DUPLICATE_ERROR</code></td>
      <td><code>-602</code></td>
      <td>选择了重复的文件</td>
    </tr>
    <tr>
      <td><code>IMAGE_FORMAT_ERROR</code></td>
      <td><code>-700</code></td>
      <td>图片格式错误</td>
    </tr>
    <tr>
      <td><code>IMAGE_MEMORY_ERROR</code></td>
      <td><code>-701</code></td>
      <td>内存错误</td>
    </tr>
    <tr>
      <td><code>IMAGE_DIMENSIONS_ERROR</code></td>
      <td><code>-702</code></td>
      <td>图片文件大小超出能处理的范围</td>
    </tr>
  </tbody>
</table></div></article></section>









































<section><header><h3>方法</h3></header><article><p>upload 对象实例上有如下方法：</p><h4><span class="code text-danger">showMessage(message, type, time)</span></h4><p>在上传文件界面区域上显示一个消息，该方法参数定义如下：</p><ul>
<li><code>message</code>：要显示的消息文本；</li>
<li><code>type</code>：消息类型，可选值包括 <code>'danger'</code>（危险消息，默认）、<code>'warning'</code>（警告）、<code>'info'</code>（一般），<code>'success'</code>（成功消息）。</li>
</ul><p>要启用显示消息功能，你必须在 <code>.upload</code> 元素内部提供 <code>.uploader-message</code> 元素。</p><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-message text-center"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"content"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"close"</span><span class="tag">&gt;</span><span class="pln">×</span><span class="tag">&lt;/button&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code></pre><h4><span class="code text-danger">hideMessage()</span></h4><p>隐藏界面上的消息。</p><h4><span class="code text-danger">start()</span></h4><p>开始上传队列中的文件。</p><h4><span class="code text-danger">stop()</span></h4><p>停止上传队列中的文件。</p><h4><span class="code text-danger">getState()</span></h4><p>获取上传队列状态代码。状态代码为 <code>$.zui.Uploader.STATUS</code> 对象上的属性值，可能的值包括 <code>$.zui.Uploader.STATUS.STARTED</code> 和 <code>$.zui.Uploader.STATUS.STOPPED</code>。</p><h4><span class="code text-danger">isStarted()</span></h4><p>检查是否正在上传队列中的文件。如果返回 <code>true</code> 则表示已开始上传，<code>false</code> 表示当前没有进行上传文件。</p><h4><span class="code text-danger">isStopped()</span></h4><p>检查是否已停止上传队列中的文件。如果返回 <code>true</code> 则表示还没有开始上传，或者上传已暂停或已上传完成，<code>false</code> 表示正在进行上传文件。</p><h4><span class="code text-danger">getFiles()</span></h4><p>获取上传队列中的文件，返回结果为文件对象数组。</p><h4><span class="code text-danger">getTotal()</span></h4><p>获取文件上传队列进度信息。参见本页面 [对象及属性 → 文件上传队列进度信息]。</p><h4><span class="code text-danger">disableBrowse(disable)</span></h4><p>设置选择文件按钮的禁用状态，参数定义如下：</p><ul>
<li><code>disable</code>：如果为 <code>true</code> 则将选择文件按钮设置为禁用，如果为 <code>false</code> 则取消选择文件按钮的禁用状态。</li>
</ul><h4><span class="code text-danger">getFile(id)</span></h4><p>通过文件 ID 获取文件对象，参数定义如下：</p><ul>
<li><code>id</code>：文件对象的唯一 ID 值。</li>
</ul><h4><span class="code text-danger">showFile(file)</span></h4><p>在文件列表上显示文件（根据文件对象 ID 属性来判断，如果文件列表上有相同 ID 的文件，则更新，否则在文件列表上新增一项），参数定义如下：</p><ul>
<li><code>file</code>：要显示的文件对象，或者为多个要显示的文件对象数组。</li>
</ul><h4><span class="code text-danger">removeFile(file)</span></h4><p>将文件从文件队列中移除，参数定义如下：</p><ul>
<li><code>file</code>：要移除的文件对象。</li>
</ul><h4><span class="code text-danger">destroy()</span></h4><p>销毁 <code>uploader</code> 实例。</p><h4><span class="code text-danger">showStatus()</span></h4><p>刷新上传进度状态信息。需要有 <code>.uploader-message</code> 元素。</p><h4>调用方法</h4><p>以调用开始上传方法 <code>start()</code> 为例：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 1. 获取 uploader 实例对象</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> uploader </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.uploader'</span><span class="pun">);</span><span class="pln">

</span><span class="com">// 2. 调用 start 方法</span><span class="pln">
uploader</span><span class="pun">.</span><span class="pln">start</span><span class="pun">();</span></code></pre></article></section>































































<section><header><h3>事件</h3></header><article><h4><span class="code text-danger">onInit</span></h4><p>当初始化完成后触发，回调函数形式为：</p><ul>
<li><code>function()</code></li>
</ul><h4><span class="code text-danger">onFilesAdded</span></h4><p>当文件被添加到上传队列时触发，回调函数形式为：</p><ul>
<li><code>function(files)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>files</code>：添加到上传队列的文件对象数组。</li>
</ul><h4><span class="code text-danger">onUploadProgress</span></h4><p>当文件上传进度发送变化时触发，此回调函数会在上传文件的过程中反复触发，回调函数形式为：</p><ul>
<li><code>function(file)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>file</code>：上传进度发生变化的文件对象。</li>
</ul><h4><span class="code text-danger">onFileUploaded</span></h4><p>当队列中的一个文件上传完成后触发，回调函数形式为：</p><ul>
<li><code>function(file, responseObject)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>file</code>：上传进度发生变化的文件对象；</li>
<li><code>responseObject</code>：服务器返回的信息对象，包含如下属性：<ul>
<li><code>response</code>：服务器返回的文本信息；</li>
<li><code>responseHeaders</code>：服务器返回的头部信息；</li>
<li><code>status</code>：HTTP 状态码，例如 <code>200</code>。</li>
</ul>
</li>
</ul><h4><span class="code text-danger">onUploadComplete</span></h4><p>当队列中所有文件上传完成后触发，回调函数形式为：</p><ul>
<li><code>function(files)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>files</code>：上传完成的文件对象数组。</li>
</ul><h4><span class="code text-danger">onFilesRemoved</span></h4><p>当文件从上传队列移除后触发，回调函数形式为：</p><ul>
<li><code>function(files)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>files</code>：被移除的文件对象数组。</li>
</ul><h4><span class="code text-danger">onChunkUploaded</span></h4><p>当启用分片上传选项后，每个文件片段上传完成时触发，回调函数形式为：</p><ul>
<li><code>function(file, responseObject)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>file</code>：上传进度发生变化的文件对象；</li>
<li><code>responseObject</code>：服务器返回的信息对象，包含如下属性：<ul>
<li><code>offset</code>：当前上传的文件片段在文件总大小中的偏移；</li>
<li><code>response</code>：服务器返回的文本信息；</li>
<li><code>responseHeaders</code>：服务器返回的头部信息；</li>
<li><code>status</code>：HTTP 状态码，例如 <code>200</code>；</li>
<li><code>total</code>：当前文件的总大小，单位为字节（b）。</li>
</ul>
</li>
</ul><h4><span class="code text-danger">onUploadFile</span></h4><p>当队列中的某个文件开始上传时触发，回调函数形式为：</p><ul>
<li><code>function(file)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>file</code>：开始上传的文件对象。</li>
</ul><h4><span class="code text-danger">onBeforeUpload</span></h4><p>当队列中的某个文件开始上传之前触发，回调函数形式为：</p><ul>
<li><code>function(file)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>file</code>：开始上传的文件对象。</li>
</ul><h4><span class="code text-danger">onStateChanged</span></h4><p>当文件队列状态发生改变时触发，回调函数形式为：</p><ul>
<li><code>function(state)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>state</code>：文件队列状态，可能的值包括 <code>$.zui.Uploader.STATUS.STARTED</code> 和 <code>$.zui.Uploader.STATUS.STOPPED</code>。</li>
</ul><h4><span class="code text-danger">onQueueChanged</span></h4><p>当文件上传队列发生变化时触发，回调函数形式为：</p><ul>
<li><code>function()</code></li>
</ul><h4><span class="code text-danger">onError</span></h4><p>当发生错误时触发，回调函数形式为：</p><ul>
<li><code>function(error)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>error</code>：错误信息对象，包含如下属性：<ul>
<li><code>code</code>：错误代码，参见错误代码属性说明；</li>
<li><code>message</code>：错误消息文本；</li>
<li><code>file</code>：发生错误相关的文件对象。</li>
</ul>
</li>
</ul><h4>绑定事件</h4><p>方式一，使用 jQuery <code>$().on(event, callback)</code> 方式：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pln">$</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">().</span><span class="pln">on</span><span class="pun">(</span><span class="str">'onUploadFile'</span><span class="pun">,</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">file</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
    console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="str">'上传成功'</span><span class="pun">,</span><span class="pln"> file</span><span class="pun">);</span><span class="pln">
</span><span class="pun">});</span></code></pre><p>方式二，在初始化时作为选项绑定：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pln">$</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">({</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'...'</span><span class="pun">,</span><span class="pln">
    </span><span class="com">// ...,</span><span class="pln">
    onUploadFile</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">file</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
       console</span><span class="pun">.</span><span class="pln">log</span><span class="pun">(</span><span class="str">'上传成功'</span><span class="pun">,</span><span class="pln"> file</span><span class="pun">);</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">});</span></code></pre><h4>在事件中访问 uploader 对象</h4><p>所有事件回调函数的 <code>this</code> 变量都为当前 <code>uploader</code> 实例对象。</p></article></section>




<section><header><h3>静态文件</h3></header><article><p>在初始化对时候使用 <code>staticFiles</code> 选项指定一个文件对象数组，可以实现在文件列表显示服务器中已存在对文件。</p><div class="example">
  <div id="uploaderStaticFilesExample" class="uploader file-drag-area uploader-rename uploader-custom" data-drop-placeholder="将文件拖放至在此处。">
    <div class="uploader-message text-center">
      <div class="content"></div>
      <button type="button" class="close">×</button>
    </div>
    <div class="uploader-files file-list file-list-lg file-rename-by-click file-show-delete-action-on-done" data-drag-placeholder="请拖拽文件到此处"><div class="file file-static" id="file-fhcdlzt43k" data-status="done"><div class="file-progress-bar"></div><div class="file-wrapper"><div class="file-icon" style="color: rgb(42, 173, 31);"><i class="icon icon-file-code file-icon-js" data-type="undefined" data-ext="js"></i></div><div class="content"><div class="file-name">zui.js</div><div class="file-size small text-muted">211 KB</div></div><div class="actions"><div class="file-status" data-toggle="tooltip" data-original-title="已上传" title=""><i class="icon"></i> <span class="text"></span></div><a data-toggle="tooltip" class="btn btn-link btn-download-file" target="_blank" title="" download="zui.js" data-original-title="下载" href="http://zui.sexy"><i class="icon icon-download-alt"></i></a><button type="button" data-toggle="tooltip" class="btn btn-link btn-reset-file" title="" data-original-title="重新上传"><i class="icon icon-repeat"></i></button><button type="button" data-toggle="tooltip" class="btn btn-link btn-rename-file" title="" data-original-title="重命名"><i class="icon icon-pencil"></i></button><button type="button" data-toggle="tooltip" title="" class="btn btn-link btn-delete-file" data-original-title="移除"><i class="icon icon-trash text-danger"></i></button></div></div></div><div class="file file-static" id="file-fhcdlzt9i1" data-status="done"><div class="file-progress-bar"></div><div class="file-wrapper"><div class="file-icon" style="color: rgb(173, 31, 66);"><i class="icon icon-file-code file-icon-css" data-type="undefined" data-ext="css"></i></div><div class="content"><div class="file-name">zui.css</div><div class="file-size small text-muted">104 KB</div></div><div class="actions"><div class="file-status" data-toggle="tooltip" data-original-title="已上传" title=""><i class="icon"></i> <span class="text"></span></div><a data-toggle="tooltip" class="btn btn-link btn-download-file" target="_blank" title="" download="zui.css" data-original-title="下载"><i class="icon icon-download-alt"></i></a><button type="button" data-toggle="tooltip" class="btn btn-link btn-reset-file" title="" data-original-title="重新上传"><i class="icon icon-repeat"></i></button><button type="button" data-toggle="tooltip" class="btn btn-link btn-rename-file" title="" data-original-title="重命名"><i class="icon icon-pencil"></i></button><button type="button" data-toggle="tooltip" title="" class="btn btn-link btn-delete-file" data-original-title="移除"><i class="icon icon-trash text-danger"></i></button></div></div></div></div>
    <div class="uploader-actions">
      <div class="uploader-status pull-right text-muted"></div>
      <button type="button" class="btn btn-link uploader-btn-browse"><i class="icon icon-plus"></i> 选择文件</button>
      <button type="button" class="btn btn-link uploader-btn-start"><i class="icon icon-cloud-upload"></i> 开始上传</button>
    </div>
  <div class="uploader-btn-browse uploader-btn-hidden" style="z-index: 1;"></div><div id="html5_1c2e40kps1grtfnu12e91e0r1nb77_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: -1px; left: -1px; width: 1px; height: 1px; overflow: hidden; z-index: 0;"><input id="html5_1c2e40kps1grtfnu12e91e0r1nb77" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept=""></div><div class="uploader-btn-browse uploader-btn-hidden" style="z-index: 1;"></div><div id="html5_1dob115ue76g1ditp7s3lhnd9g_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: -1px; left: -1px; width: 1px; height: 1px; overflow: hidden; z-index: 0;"><input id="html5_1dob115ue76g1ditp7s3lhnd9g" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="" tabindex="-1"></div></div>
</div><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pln">$</span><span class="pun">(</span><span class="str">'#uploaderStaticFilesExample'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">({</span><span class="pln">
      chunk_size</span><span class="pun">:</span><span class="pln"> </span><span class="str">'50kb'</span><span class="pun">,</span><span class="pln">
      url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'http://your/post/url'</span><span class="pun">,</span><span class="pln">
      deleteActionOnDone</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">file</span><span class="pun">,</span><span class="pln"> doRemoveFile</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
          doRemoveFile</span><span class="pun">();</span><span class="pln">
      </span><span class="pun">},</span><span class="pln">
      staticFiles</span><span class="pun">:</span><span class="pln"> </span><span class="pun">[</span><span class="pln">
          </span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="pln"> </span><span class="str">'zui.js'</span><span class="pun">,</span><span class="pln"> size</span><span class="pun">:</span><span class="pln"> </span><span class="lit">216159</span><span class="pun">,</span><span class="pln"> url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'http://zui.sexy'</span><span class="pun">},</span><span class="pln">
          </span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="pln"> </span><span class="str">'zui.css'</span><span class="pun">,</span><span class="pln"> size</span><span class="pun">:</span><span class="pln"> </span><span class="lit">106091</span><span class="pun">}</span><span class="pln">
      </span><span class="pun">]</span><span class="pln">
  </span><span class="pun">});</span></code></pre></article></section>





































<section><header><h3>自定义 UI</h3></header><article><p>文件上传视图提供了最大限度的定制机制，你可以定制自己的文件上传 UI。</p><h4>HTML 结构</h4><p>在文件上传视图中约定了一些特定的类来使得你的 UI 交互生效。通常情况下文件上传视图的 HTML 结构如下：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-message"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"content"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"close"</span><span class="tag">&gt;</span><span class="pln">×</span><span class="tag">&lt;/button&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-files file-list"</span><span class="pln"> </span><span class="atn">data-drag-placeholder</span><span class="pun">=</span><span class="atv">"请拖拽文件到此处"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-actions"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-status pull-right text-muted"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link uploader-btn-browse"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-plus"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> 选择文件</span><span class="tag">&lt;/button&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link uploader-btn-start"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-cloud-upload"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> 开始上传</span><span class="tag">&lt;/button&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code></pre><p>约定的特殊类说明：</p><div class="table-responsive"><table class="table table-bordered">
  <thead>
    <tr>
      <th style="width: 160px">特殊类</th>
      <th>说明</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>.uploader</code></td>
      <td>文件上传顶层容器，你可用在此元素上使用 <code>[data-*=*]</code> 来设置初始化选项，使用 <code>[data-ride="uploader"]</code> 来启用文件加载完成时自动进行初始化。</td>
    </tr>
    <tr>
      <td><code>.uploader-files</code></td>
      <td>
        <p>文件列表，还可用同时使用如下外观类中的一个：</p>
        <ul>
          <li><code>.file-list</code>：使用默认文件列表外观；</li>
          <li><code>.file-list.file-list-lg</code>：使用大号文件列表外观；</li>
          <li><code>.file-list.file-list-grid</code>：使用网格文件列表外观。</li>
        </ul>
        <p>使用 <code>[data-drag-placeholder=""]</code>，来设置文件上传列表的预设提示文本。</p>
      </td>
    </tr>
    <tr>
      <td><code>.uploader-message</code></td>
      <td>
        <p>用于在此元素中显示交互过程中的消息。在 <code>.uploader-message</code> 内你还可以放置一个 <code>.close</code> 来指定用于关闭此消息的按钮，使用 <code>.content</code> 来指定消息文本显示的元素。一个完整的示例如下：</p>
        <pre class="prettyprint prettyprinted" style=""><code><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-message"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"content"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"close"</span><span class="tag">&gt;</span><span class="pln">×</span><span class="tag">&lt;/button&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code></pre>
      </td>
    </tr>
    <tr>
      <td><code>.uploader-actions</code></td>
      <td>用于放置文件上传操作相关按钮。</td>
    </tr>
    <tr>
      <td><code>.uploader-btn-browse</code></td>
      <td>通常用于标记一个按钮，点击此按钮会打开文件对话框。</td>
    </tr>
    <tr>
      <td><code>.uploader-btn-start</code></td>
      <td>通常用于标记一个按钮，点击此按钮会开始（或恢复）上传文件队列中的文件到服务器。</td>
    </tr>
    <tr>
      <td><code>.uploader-btn-stop</code></td>
      <td>通常用于标记一个按钮，点击此按钮会暂停上传文件队列中的文件到服务器。</td>
    </tr>
    <tr>
      <td><code>.uploader-status</code></td>
      <td>用于在此元素中显示文件上传状态信息，包括文件上传进度、实时速度或文件数量等。</td>
    </tr>
  </tbody>
</table></div><h4>自定义文件元素模板</h4><p>文件元素模板决定如何在文件列表上显示一个文件条目。默认的模板为：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-progress-bar"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-wrapper"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-icon"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-file-o"</span><span class="tag">&gt;&lt;/i&gt;&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"content"</span><span class="tag">&gt;</span><span class="pln">
      </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-name"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
      </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-size small text-muted"</span><span class="tag">&gt;</span><span class="pln">0KB</span><span class="tag">&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"actions"</span><span class="tag">&gt;</span><span class="pln">
      </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-status"</span><span class="pln"> </span><span class="atn">data-toggle</span><span class="pun">=</span><span class="atv">"tooltip"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> </span><span class="tag">&lt;span</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"text"</span><span class="tag">&gt;&lt;/span&gt;&lt;/div&gt;</span><span class="pln">
      </span><span class="tag">&lt;a</span><span class="pln"> </span><span class="atn">data-toggle</span><span class="pun">=</span><span class="atv">"tooltip"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link btn-download-file"</span><span class="pln"> </span><span class="atn">target</span><span class="pun">=</span><span class="atv">"_blank"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-download-alt"</span><span class="tag">&gt;&lt;/i&gt;&lt;/a&gt;</span><span class="pln">
      </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">data-toggle</span><span class="pun">=</span><span class="atv">"tooltip"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link btn-reset-file"</span><span class="pln"> </span><span class="atn">title</span><span class="pun">=</span><span class="atv">"Repeat"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-repeat"</span><span class="tag">&gt;&lt;/i&gt;&lt;/button&gt;</span><span class="pln">
      </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">data-toggle</span><span class="pun">=</span><span class="atv">"tooltip"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link btn-rename-file"</span><span class="pln"> </span><span class="atn">title</span><span class="pun">=</span><span class="atv">"Rename"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-pencil"</span><span class="tag">&gt;&lt;/i&gt;&lt;/button&gt;</span><span class="pln">
      </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">data-toggle</span><span class="pun">=</span><span class="atv">"tooltip"</span><span class="pln"> </span><span class="atn">title</span><span class="pun">=</span><span class="atv">"Remove"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link btn-delete-file"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-trash text-danger"</span><span class="tag">&gt;&lt;/i&gt;&lt;/button&gt;</span><span class="pln">
    </span><span class="tag">&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code></pre><p>有两种方式来设置文件元素模板。方式一是通过初始化选项 <code>fileTemplate</code>：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pln">$</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">({</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'...'</span><span class="pun">,</span><span class="pln">
    </span><span class="com">// ...</span><span class="pln">
    fileTemplate</span><span class="pun">:</span><span class="pln"> </span><span class="str">"..."</span><span class="pln"> </span><span class="com">// 设置文件模板字符串</span><span class="pln">
</span><span class="pun">});</span></code></pre><p>方式二是通过在 <code>.uploader-files</code> 元素内使用 <code>.template</code> 类来标记一个元素作为文件模板：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">'uploaderExample2'</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="pln"> </span><span class="atn">data-ride</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="pln"> </span><span class="atn">data-url</span><span class="pun">=</span><span class="atv">"your/file/upload/url"</span><span class="pln"> </span><span class="atn">data-auto-upload</span><span class="pun">=</span><span class="atv">"true"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-files file-list"</span><span class="pln"> </span><span class="atn">data-drag-placeholder</span><span class="pun">=</span><span class="atv">"请拖拽文件到此处"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file template"</span><span class="tag">&gt;</span><span class="pln">
      </span><span class="com">&lt;!-- 文件模板元素内部内容 --&gt;</span><span class="pln">
    </span><span class="tag">&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code></pre><p>文件元素模板中可以使用如下约定的特殊类：</p><div class="table-responsive"><table class="table table-bordered">
  <thead>
    <tr>
      <th>类</th>
      <th>说明</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>.file</code></td>
      <td>文件元素容器类</td>
    </tr>
    <tr>
      <td><code>.file-progress-bar</code></td>
      <td>文件上传进度条</td>
    </tr>
    <tr>
      <td><code>.file-icon</code></td>
      <td>用于显示文件图标</td>
    </tr>
    <tr>
      <td><code>.file-name</code></td>
      <td>用于显示文件名</td>
    </tr>
    <tr>
      <td><code>.file-size</code></td>
      <td>用于显示文件大小</td>
    </tr>
    <tr>
      <td><code>.file-status</code></td>
      <td>用于显示文件状态信息</td>
    </tr>
    <tr>
      <td><code>.btn-download-file</code></td>
      <td>用户点击此元素触发文件下载操作</td>
    </tr>
    <tr>
      <td><code>.btn-reset-file</code></td>
      <td>用户点击此元素触发重新上传操作</td>
    </tr>
    <tr>
      <td><code>.btn-rename-file</code></td>
      <td>用户点击此元素触发文件重命名操作</td>
    </tr>
    <tr>
      <td><code>.btn-delete-file</code></td>
      <td>用户点击此元素触发移除文件操作</td>
    </tr>
  </tbody>
</table></div><p>文件模板中也可以完全不用约定的特殊类（<code>.file</code> 类除外），通过初始化选项 <code>fileFormater</code> 指定一个回调函数来格式化文件元素，该回调函数定义为：</p><ul>
<li><code>function($file, file, status)</code></li>
</ul><p>参数定义如下：</p><ul>
<li><code>$file</code>：要格式化的文件元素；</li>
<li><code>file</code>：当前文件对象；</li>
<li><code>status</code>：当前文件状态。</li>
</ul><p>回调函数中 <code>this</code> 变量为当前 <code>uploader</code> 实例。</p><p>简单的回调函数例子：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pln">$</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">({</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'...'</span><span class="pun">,</span><span class="pln">
    </span><span class="com">// ...</span><span class="pln">
    fileFormater</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">$file</span><span class="pun">,</span><span class="pln"> file</span><span class="pun">,</span><span class="pln"> status</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        $file</span><span class="pun">.</span><span class="pln">find</span><span class="pun">(</span><span class="str">'.file-name'</span><span class="pun">).</span><span class="pln">text</span><span class="pun">(</span><span class="pln">file</span><span class="pun">.</span><span class="pln">name</span><span class="pun">);</span><span class="pln">
        </span><span class="com">// ...</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">});</span></code></pre><h4>自定义文件图标</h4><p>默认情况下会为不同的文件类型显示不同的文件图标，也可以通过初始化选项 <code>fileIconCreator</code> 指定一个回调函数来返回用于显示图标的 HTML 源码，该回调函数定义为：</p><ul>
<li><code>function(fileType, file, uploader)</code></li>
</ul><p>回调函数参数定义如下：</p><ul>
<li><code>fileType</code>：文件类型，例如 <code>'image/jpeg'</code>；</li>
<li><code>file</code>：文件对象；</li>
<li><code>uploader</code>：uploader 实例对象。</li>
</ul><p>例子：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pln">$</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">({</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'...'</span><span class="pun">,</span><span class="pln">
    </span><span class="com">// ...</span><span class="pln">
    fileIconCreator</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">fileType</span><span class="pun">,</span><span class="pln"> file</span><span class="pun">,</span><span class="pln"> uploader</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">fileType</span><span class="pun">.</span><span class="pln">indexOf</span><span class="pun">(</span><span class="str">'image'</span><span class="pun">)</span><span class="pln"> </span><span class="pun">===</span><span class="pln"> </span><span class="lit">0</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
            </span><span class="com">// 如果文件是图片，返回图片图标</span><span class="pln">
            </span><span class="kwd">return</span><span class="pln"> </span><span class="str">'&lt;i class="icon icon-file-image"&gt;&lt;/i&gt;'</span><span class="pun">;</span><span class="pln">
        </span><span class="pun">}</span><span class="pln"> </span><span class="kwd">else</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
            </span><span class="com">// 处理其他非图片文件情况</span><span class="pln">
        </span><span class="pun">}</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">})</span></code></pre><h4>定制示例</h4><p>下面给出一个用表格来显示文件列表的例子。</p><div class="example">
  <div id="tableUploader" class="uploader file-drag-area uploader-rename" data-drop-placeholder="将文件拖放至在此处。">
    <div class="uploader-message text-center">
      <div class="content"></div>
      <button type="button" class="close">×</button>
    </div>
    <table class="table table-bordered">
      <thead>
        <tr>
          <th colspan="2">文件名</th>
          <th style="width: 100px">大小</th>
          <th style="width: 160px; text-align: center;">状态/操作</th>
        </tr>
      </thead>
      <tbody class="uploader-files file-rename-by-click">
        
      </tbody>
      <tfoot>
        <tr>
          <td colspan="4" style="padding: 4px 0">
            <div style="position: relative;">
              <div class="uploader-status pull-right text-muted" style="margin-top: 5px;"></div>
              <button type="button" class="btn btn-link uploader-btn-browse"><i class="icon icon-plus"></i> 选择文件</button>
              <button type="button" class="btn btn-link uploader-btn-start"><i class="icon icon-cloud-upload"></i> 开始上传</button>
            </div>
          </td>
        </tr>
      </tfoot>
    </table>
  <div class="uploader-btn-browse uploader-btn-hidden" style="z-index: 1;"></div><div id="html5_1dob115uag9310chqa41q1nlcld_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: -1px; left: -1px; width: 1px; height: 1px; overflow: hidden; z-index: 0;"><input id="html5_1dob115uag9310chqa41q1nlcld" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="" tabindex="-1"></div></div>
</div><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">id</span><span class="pun">=</span><span class="atv">"tableUploader"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader"</span><span class="tag">&gt;</span><span class="pln">
  </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-message text-center"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"content"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
    </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"close"</span><span class="tag">&gt;</span><span class="pln">×</span><span class="tag">&lt;/button&gt;</span><span class="pln">
  </span><span class="tag">&lt;/div&gt;</span><span class="pln">
  </span><span class="tag">&lt;table</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"table table-bordered"</span><span class="tag">&gt;</span><span class="pln">
    </span><span class="tag">&lt;thead&gt;</span><span class="pln">
      </span><span class="tag">&lt;tr&gt;</span><span class="pln">
        </span><span class="tag">&lt;th</span><span class="pln"> </span><span class="atn">colspan</span><span class="pun">=</span><span class="atv">"2"</span><span class="tag">&gt;</span><span class="pln">文件名</span><span class="tag">&lt;/th&gt;</span><span class="pln">
        </span><span class="tag">&lt;th</span><span class="pln"> </span><span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">width</span><span class="pun">:</span><span class="pln"> </span><span class="lit">100px</span><span class="atv">"</span><span class="tag">&gt;</span><span class="pln">大小</span><span class="tag">&lt;/th&gt;</span><span class="pln">
        </span><span class="tag">&lt;th</span><span class="pln"> </span><span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">width</span><span class="pun">:</span><span class="pln"> </span><span class="lit">160px</span><span class="pun">;</span><span class="pln"> text</span><span class="pun">-</span><span class="pln">align</span><span class="pun">:</span><span class="pln"> center</span><span class="pun">;</span><span class="atv">"</span><span class="tag">&gt;</span><span class="pln">状态/操作</span><span class="tag">&lt;/th&gt;</span><span class="pln">
      </span><span class="tag">&lt;/tr&gt;</span><span class="pln">
    </span><span class="tag">&lt;/thead&gt;</span><span class="pln">
    </span><span class="tag">&lt;tbody</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-files"</span><span class="tag">&gt;</span><span class="pln">
      </span><span class="tag">&lt;tr</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file template"</span><span class="tag">&gt;</span><span class="pln">
        </span><span class="tag">&lt;td</span><span class="pln"> </span><span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">width</span><span class="pun">:</span><span class="pln"> </span><span class="lit">38px</span><span class="pun">;</span><span class="pln"> padding</span><span class="pun">:</span><span class="pln"> </span><span class="lit">3px</span><span class="atv">"</span><span class="tag">&gt;&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-icon"</span><span class="tag">&gt;&lt;/div&gt;&lt;/td&gt;</span><span class="pln">
        </span><span class="tag">&lt;td</span><span class="pln"> </span><span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">padding</span><span class="pun">:</span><span class="pln"> </span><span class="lit">0</span><span class="atv">"</span><span class="tag">&gt;</span><span class="pln">
          </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">position</span><span class="pun">:</span><span class="pln"> relative</span><span class="pun">;</span><span class="pln"> padding</span><span class="pun">:</span><span class="pln"> </span><span class="lit">8px</span><span class="pun">;</span><span class="atv">"</span><span class="tag">&gt;</span><span class="pln">
            </span><span class="tag">&lt;strong</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-name"</span><span class="tag">&gt;&lt;/strong&gt;</span><span class="pln">
            </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-progress-bar"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
          </span><span class="tag">&lt;/div&gt;</span><span class="pln">
        </span><span class="tag">&lt;/td&gt;</span><span class="pln">
        </span><span class="tag">&lt;td&gt;&lt;span</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-size text-muted"</span><span class="tag">&gt;&lt;/span&gt;&lt;/td&gt;</span><span class="pln">
        </span><span class="tag">&lt;td</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"actions text-right"</span><span class="pln"> </span><span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">padding</span><span class="pun">:</span><span class="pln"> </span><span class="lit">0</span><span class="pln"> </span><span class="lit">4px</span><span class="pun">;</span><span class="atv">"</span><span class="tag">&gt;</span><span class="pln">
          </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"file-status"</span><span class="pln"> </span><span class="atn">data-toggle</span><span class="pun">=</span><span class="atv">"tooltip"</span><span class="pln"> </span><span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">margin</span><span class="pun">:</span><span class="pln"> </span><span class="lit">8px</span><span class="pun">;</span><span class="atv">"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> </span><span class="tag">&lt;span</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"text"</span><span class="tag">&gt;&lt;/span&gt;&lt;/div&gt;</span><span class="pln">
          </span><span class="tag">&lt;a</span><span class="pln"> </span><span class="atn">data-toggle</span><span class="pun">=</span><span class="atv">"tooltip"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link btn-download-file"</span><span class="pln"> </span><span class="atn">target</span><span class="pun">=</span><span class="atv">"_blank"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-download-alt"</span><span class="tag">&gt;&lt;/i&gt;&lt;/a&gt;</span><span class="pln">
          </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">data-toggle</span><span class="pun">=</span><span class="atv">"tooltip"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link btn-reset-file"</span><span class="pln"> </span><span class="atn">title</span><span class="pun">=</span><span class="atv">"Repeat"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-repeat"</span><span class="tag">&gt;&lt;/i&gt;&lt;/button&gt;</span><span class="pln">
          </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">data-toggle</span><span class="pun">=</span><span class="atv">"tooltip"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link btn-rename-file"</span><span class="pln"> </span><span class="atn">title</span><span class="pun">=</span><span class="atv">"Rename"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-pencil"</span><span class="tag">&gt;&lt;/i&gt;&lt;/button&gt;</span><span class="pln">
          </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">data-toggle</span><span class="pun">=</span><span class="atv">"tooltip"</span><span class="pln"> </span><span class="atn">title</span><span class="pun">=</span><span class="atv">"Remove"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link btn-delete-file"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-trash text-danger"</span><span class="tag">&gt;&lt;/i&gt;&lt;/button&gt;</span><span class="pln">
        </span><span class="tag">&lt;/td&gt;</span><span class="pln">
      </span><span class="tag">&lt;/tr&gt;</span><span class="pln">
    </span><span class="tag">&lt;/tbody&gt;</span><span class="pln">
    </span><span class="tag">&lt;tfoot&gt;</span><span class="pln">
      </span><span class="tag">&lt;tr&gt;</span><span class="pln">
        </span><span class="tag">&lt;td</span><span class="pln"> </span><span class="atn">colspan</span><span class="pun">=</span><span class="atv">"4"</span><span class="pln"> </span><span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">padding</span><span class="pun">:</span><span class="pln"> </span><span class="lit">4px</span><span class="pln"> </span><span class="lit">0</span><span class="atv">"</span><span class="tag">&gt;</span><span class="pln">
          </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">position</span><span class="pun">:</span><span class="pln"> relative</span><span class="pun">;</span><span class="atv">"</span><span class="tag">&gt;</span><span class="pln">
            </span><span class="tag">&lt;div</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"uploader-status pull-right text-muted"</span><span class="pln"> </span><span class="atn">style</span><span class="pun">=</span><span class="atv">"</span><span class="pln">margin</span><span class="pun">-</span><span class="pln">top</span><span class="pun">:</span><span class="pln"> </span><span class="lit">5px</span><span class="pun">;</span><span class="atv">"</span><span class="tag">&gt;&lt;/div&gt;</span><span class="pln">
            </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link uploader-btn-browse"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-plus"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> 选择文件</span><span class="tag">&lt;/button&gt;</span><span class="pln">
            </span><span class="tag">&lt;button</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"button"</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"btn btn-link uploader-btn-start"</span><span class="tag">&gt;&lt;i</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"icon icon-cloud-upload"</span><span class="tag">&gt;&lt;/i&gt;</span><span class="pln"> 开始上传</span><span class="tag">&lt;/button&gt;</span><span class="pln">
          </span><span class="tag">&lt;/div&gt;</span><span class="pln">
        </span><span class="tag">&lt;/td&gt;</span><span class="pln">
      </span><span class="tag">&lt;/tr&gt;</span><span class="pln">
    </span><span class="tag">&lt;/tfoot&gt;</span><span class="pln">
  </span><span class="tag">&lt;/table&gt;</span><span class="pln">
</span><span class="tag">&lt;/div&gt;</span></code></pre><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pln">$</span><span class="pun">(</span><span class="str">'#tableUploader'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">({</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'url/for/upload/file'</span><span class="pln">
</span><span class="pun">});</span></code></pre></article></section>














<section><header><h3>处理服务器结果</h3></header><article><h4>默认处理方式</h4><p>通常当服务器对上传的文件的 HTTP 请求状态为 <code>200</code> 则视为文件上传成功，否则视为文件上传失败。如果需要返回更加详细的错误信息，可以返回 JSON 对象字符串。在 JSON 对象中设置 <code>result</code> 或 <code>status</code> 属性值为 <code>'ok'</code>、<code>'success'</code>、<code>200</code> 中的一个则视为文件上传成功，否则视为文件上传失败。</p><p>当文件上传失败时，使用 <code>message</code> 属性返回一个错误消息在界面上显示来提示用户。下面为当文件上传失败时一个完整的 JSON 对象示例：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pun">{</span><span class="pln">
    result</span><span class="pun">:</span><span class="pln"> </span><span class="str">'failed'</span><span class="pun">,</span><span class="pln">               </span><span class="com">// 文件上传失败</span><span class="pln">
    message</span><span class="pun">:</span><span class="pln"> </span><span class="str">'文件内容包含违规内容'</span><span class="pln">    </span><span class="com">// 用于在界面上提示用户的消息</span><span class="pln">
</span><span class="pun">}</span></code></pre><p>当文件上传成功时，使用 <code>id</code> 属性来返回文件在服务器上的唯一标识，使用 <code>url</code> 属性返回文件的下载地址。当下载地址指定时会在文件列表上显示该文件的下载按钮。下面为当文件上传成功时的一个完整的 JSON 对象示例：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pun">{</span><span class="pln">
    result</span><span class="pun">:</span><span class="pln"> </span><span class="str">'ok'</span><span class="pun">,</span><span class="pln">     </span><span class="com">// 文件上传成功</span><span class="pln">
    id</span><span class="pun">:</span><span class="pln"> </span><span class="lit">10001</span><span class="pun">,</span><span class="pln">        </span><span class="com">// 文件在服务器上的唯一标识</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'http://example.com/file-10001.jpg'</span><span class="pln">        </span><span class="com">// 文件的下载地址</span><span class="pln">
</span><span class="pun">}</span></code></pre><h4>自定义处理方式</h4><p>除了直接通过返回约定格式的 JSON 对象来判断上传结果之外，还可以通过初始化选项 <code>responseHandler</code> 设置一个回调函数来自定义处理结果。</p><p>该回调函数定义为：</p><ul>
<li><code>function(responseObject, file)</code></li>
</ul><p>参数定义为：</p><ul>
<li><code>responseObject</code>：服务器返回的信息对象，包含如下属性：<ul>
<li><code>response</code>：服务器返回的文本信息；</li>
<li><code>responseHeaders</code>：服务器返回的头部信息；</li>
<li><code>status</code>：HTTP 状态码，例如 <code>200</code>。</li>
</ul>
</li>
<li><code>file</code>：当前上传的文件对象。</li>
</ul><p>该回调函数的 <code>this</code> 变量指向 uploader 当前实例。在该回调函数中返回任何字符串都视为上传失败，并将返回的字符串作为错误消息显示在用户界面上。</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pln">$</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">({</span><span class="pln">
    url</span><span class="pun">:</span><span class="pln"> </span><span class="str">'url/for/upload/file'</span><span class="pun">,</span><span class="pln">
    </span><span class="com">// ...</span><span class="pln">
    responseHandler</span><span class="pun">:</span><span class="pln"> </span><span class="kwd">function</span><span class="pun">(</span><span class="pln">responseObject</span><span class="pun">,</span><span class="pln"> file</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        </span><span class="com">// 当服务器返回的文本内容包含 `'error'` 文本时视为上传失败</span><span class="pln">
        </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">responseObject</span><span class="pun">.</span><span class="pln">response</span><span class="pun">.</span><span class="pln">indexOf</span><span class="pun">(</span><span class="str">'error'</span><span class="pun">))</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
            </span><span class="kwd">return</span><span class="pln"> </span><span class="str">'上传失败。服务器返回了一个错误：'</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> responseObject</span><span class="pun">.</span><span class="pln">response</span><span class="pun">;</span><span class="pln">
        </span><span class="pun">}</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">});</span></code></pre></article></section>
















<section><header><h3>使用七牛 Javascript SDK</h3></header><article><p>文件上传支持配合七牛云存储使用，当检测到页面加载了 <a href="http://github.com/qiniu/js-sdk" target="_blank">七牛 JavaScript SDK</a> 后，只需要在初始化选项 <code>qiniu</code> 指定七牛 API 相关信息即可将文件上传到七牛。</p><p>初始化选项 <code>qiniu</code> 为一个对象，应该包含如下属性：</p><div class="table-responsive"><table class="table table-bordered">
  <thead>
    <tr>
      <th>属性</th>
      <th>描述</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>domain</code></td>
      <td><strong>必需</strong>，bucket 域名，上传下载资源时用到，如：'<a href="http://xxx.bkt.clouddn.com/">http://xxx.bkt.clouddn.com/</a>'</td>
    </tr>
    <tr>
      <td><code>uptoken</code></td>
      <td>是上传凭证，由其他程序生成</td>
    </tr>
    <tr>
      <td><code>uptoken_url</code></td>
      <td>Ajax 请求 uptoken 的 Url，<strong>强烈建议设置</strong>（服务端提供）</td>
    </tr>
    <tr>
      <td><code>uptoken_func</code></td>
      <td>在需要获取 uptoken 时，该方法会被调用</td>
    </tr>
  </tbody>
</table></div><p>属性 <code>uptoken</code>、<code>uptoken_url</code>、<code>uptoken_func</code> 至少且仅需指定一个。以下为一个完整的七牛配置对象：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pun">{</span><span class="pln">
    uptoken </span><span class="pun">:</span><span class="pln"> </span><span class="str">'u0nP4wf4t7V3-5gniRcZ3EdvScOLpZkokruvCB7V:apjkB76CaKkP2nNFwuoEvmxE9NU=:eyJzY29wZSI6ImNhdG91c2UiLCJkZWFkbGluZSI6MTQ4MTcyODAzMH0='</span><span class="pun">,</span><span class="pln">
    domain</span><span class="pun">:</span><span class="pln"> </span><span class="str">'http://7xjyuk.com1.z0.glb.clouddn.com'</span><span class="pln">
</span><span class="pun">}</span></code></pre><p>更多内容请参考 <a href="https://developer.qiniu.com/kodo/sdk/javascript" target="_blank">七牛官方文档</a>。</p><h4>使用七牛上传的步骤</h4><p>第一步：在页面引入七牛 <a href="https://github.com/qiniu/js-sdk">js-sdk</a>：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-html"><span class="com">&lt;!-- 在 zui.js 和 uploader.js 加载之前引入七牛 js-sdk --&gt;</span><span class="pln">
</span><span class="tag">&lt;script</span><span class="pln"> </span><span class="atn">src</span><span class="pun">=</span><span class="atv">"https://cdn.staticfile.org/qiniu-js-sdk/1.0.14-beta/qiniu.min.js"</span><span class="tag">&gt;&lt;/script&gt;</span></code></pre><p>第二步：在初始化选项中指定 <code>qiniu</code> 配置对象：</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="pln">$</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">uploader</span><span class="pun">({</span><span class="pln">
    qiniu</span><span class="pun">:</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
        uptoken </span><span class="pun">:</span><span class="pln"> </span><span class="str">''</span><span class="pun">,</span><span class="pln">
        domain</span><span class="pun">:</span><span class="pln"> </span><span class="str">'http://7xjyuk.com1.z0.glb.clouddn.com'</span><span class="pln">
    </span><span class="pun">}</span><span class="pln">
</span><span class="pun">});</span></code></pre><p>在选项中指定了 <code>qiniu</code> 配置对象之后，无需指定 <code>url</code> 选项。</p><div class="example">
  <div class="input-group" style="margin-bottom: 10px; max-width: 400px">
    <span class="input-group-addon">七牛 SDK token</span>
    <input id="qiniuToken" type="text" class="form-control" placeholder="输入token 在下面测试" value="">
  </div>
  <div id="qiniuUploaderExample" class="uploader uploader-custom file-drag-area uploader-rename" data-drop-placeholder="将文件拖放至在此处。">
    <div class="uploader-files file-list file-rename-by-click" data-drag-placeholder="请拖拽文件到此处，文件将上传到七牛"></div>
    <button type="button" class="btn btn-primary uploader-btn-browse"><i class="icon icon-cloud-upload"></i> 选择文件</button>
    <button type="button" class="btn btn-primary uploader-btn-start"><i class="icon icon-cloud-upload"></i> 开始上传文件到七牛</button>
  <div class="uploader-btn-browse uploader-btn-hidden" style="z-index: 1;"></div><div id="html5_1dob115us1ci9puj1ijl1ioa1tg9j_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: -1px; left: -1px; width: 1px; height: 1px; overflow: hidden; z-index: 0;"><input id="html5_1dob115us1ci9puj1ijl1ioa1tg9j" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="" tabindex="-1"></div></div>
</div><p>如果仅仅需要测试七牛文件上传功能，可以使用 <a target="_blank" href="http://jsfiddle.net/gh/get/extjs/4.2/icattlecoder/jsfiddle/tree/master/uptoken">上传凭证在线生成工具</a>。</p></article></section>

<section><header><h3>获取 plupload 对象</h3></header><article><p>文件上传视图基于 <a href="http://www.plupload.com/" target="_blank">plupload</a> 开发，你仍然可以从 <code>uploader</code> 对象上获取到原始的 <code>plupload</code> 对象。</p><pre class="prettyprint prettyprinted" style=""><code class="lang-js"><span class="com">// 获取 uploader 对象</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> uploader </span><span class="pun">=</span><span class="pln"> $</span><span class="pun">(</span><span class="str">'#myUploader'</span><span class="pun">).</span><span class="pln">data</span><span class="pun">(</span><span class="str">'zui.uploader'</span><span class="pun">);</span><span class="pln">
</span><span class="com">// 获取 plupload 对象</span><span class="pln">
</span><span class="kwd">var</span><span class="pln"> plupload </span><span class="pun">=</span><span class="pln"> uploader</span><span class="pun">.</span><span class="pln">plupload</span><span class="pun">;</span></code></pre><p><code>plupload</code> 对象上可用的属性和方法如下：</p><div class="table-responsive"><table class="table table-bordered">
  <thead>
    <tr>
      <th>属性/方法</th>
      <th>说明</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>id</code></td>
      <td>plupload 的 ID，在页面上值唯一</td>
    </tr>
    <tr>
      <td><code>state</code></td>
      <td>当前的上传队列状态，可选值包括：<code>$.zui.Uploader.STATUS.STARTED</code> 和 <code>$.zui.Uploader.STATUS.STOPPED</code></td>
    </tr>
    <tr>
      <td><code>runtime</code></td>
      <td>当前使用的上传方式</td>
    </tr>
    <tr>
      <td><code>files</code></td>
      <td>当前上传队列中的文件，值为一个包含所有文件对象的数组</td>
    </tr>
    <tr>
      <td><code>settings</code></td>
      <td>当前的配置选项对象</td>
    </tr>
    <tr>
      <td><code>total</code></td>
      <td>文件上传队列进度信息</td>
    </tr>
  </tbody>
</table></div><div class="alert alert-warning">
  <h4>提示</h4>
  <p>不推荐直接操作 <code>plupload</code> 对象，一般情况下 <code>uploader</code> 对象方法可以实现绝大部分功能。</p>
</div></article></section></div>

</section>
{/block}
{block name="script"}
<!-- 在 zui.js 和 uploader.js 加载之前引入七牛 js-sdk -->
<script src="https://cdn.staticfile.org/qiniu-js-sdk/1.0.14-beta/qiniu.min.js"></script>
<script src="__ZUI__/lib/uploader/zui.uploader.js"></script>


<script>
$(function(){
  afterPageLoad();
});

function afterPageLoad() {
    $('.uploader:not(.uploader-custom)').uploader({
        chunk_size: '50kb',
        url: window.location.protocol + '//httpbin.org/post'
    });

    $('#uploaderStaticFilesExample').uploader({
        chunk_size: '50kb',
        url: window.location.protocol + '//httpbin.org/post',
        deleteActionOnDone: function(file, doRemoveFile) {
            doRemoveFile();
        },
        staticFiles: [
            {name: 'zui.js', size: 216159, url: 'http://zui.sexy'},
            {name: 'zui.css', size: 106091}
        ]
    });

    $('#qiniuUploaderExample').uploader({
        qiniu: {
            uptoken : 'fake-qiniu-token',
            domain: 'http://7xjyuk.com1.z0.glb.clouddn.com'
        },
        multipart_params: function(file) {
            return {
                token: $('#qiniuToken').val()
            };
        }
    })
}
</script>
{/block}